<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>下游客户管理</title>
	<meta name="decorator" content="ani"/>
	<script type="text/javascript">
		var validateForm;
		var $table; // 父页面table表格id
		var $topIndex;//弹出窗口的 index
		function doSubmit(table, index){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
		  if(validateForm.form()){
			  $table = table;
			  $topIndex = index;
			  jp.loading();
			  $("#inputForm").submit();
			  return true;
		  }

		  return false;
		}

		$(document).ready(function() {
			validateForm = $("#inputForm").validate({
				submitHandler: function(form){
					jp.post("${ctx}/infor/newCustomers/save",$('#inputForm').serialize(),function(data){
						if(data.success){
	                    	$table.bootstrapTable('refresh');
	                    	jp.success(data.msg);
	                    	jp.close($topIndex);//关闭dialog

	                    }else{
            	  			jp.error(data.msg);
	                    }
					})
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
		});
		
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
			$(list+idx).find(".form_datetime").each(function(){
				 $(this).datetimepicker({
					 format: "YYYY-MM-DD HH:mm:ss"
			    });
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
</head>
<body class="bg-white">
		<form:form id="inputForm" modelAttribute="newCustomers" action="${ctx}/infor/newCustomers/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<table class="table table-bordered">
		   <tbody>

				<tr>
					<td class="width-15 active"><label class="pull-right">一级客户名称：</label></td>
					<td class="width-35">
						<form:input path="khmc" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">收货单位名称：</label></td>
					<td class="width-35">
						<form:input path="dwmc" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">客户类型(自有客户，外部客户)：</label></td>
					<td class="width-35">
						<form:select path="type" class="form-control ">
							<form:options items="${fns:getDictList('khType')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
					<td class="width-15 active"><label class="pull-right">收货详细地址：</label></td>
					<td class="width-35">
						<form:input path="site" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">收货确认人：</label></td>
					<td class="width-35">
						<form:input path="qrr" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">确认人电话：</label></td>
					<td class="width-35">
						<form:input path="qrrdh" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">到站省：</label></td>
					<td class="width-35">
						<form:input path="dzs" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">到站地城市：</label></td>
					<td class="width-35">
						<form:input path="dzcs" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">起运地：</label></td>
					<td class="width-35">
						<sys:gridselect    url="${ctx}/infor/start/data" id="qyd" name="qyd.id" value="${newCustomers.qyd.id}" labelName="qyd.name" labelValue="${newCustomers.qyd.name}"
										   title="选择结算地" cssClass="form-control required" fieldLabels="名称" fieldKeys="name" searchLabels="结算地" searchKeys="name"  ></sys:gridselect>


					</td>
					<td class="width-15 active"><label class="pull-right">结算地：</label></td>
					<td class="width-35">
						<sys:gridselect    url="${ctx}/infor/settlement/data" id="jsd" name="jsd.id" value="${newCustomers.jsd.id}" labelName="jsd.name" labelValue="${newCustomers.jsd.name}"
										   title="选择结算地" cssClass="form-control required" fieldLabels="名称" fieldKeys="name" searchLabels="结算地" searchKeys="name"  ></sys:gridselect>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">运输线路：</label></td>
					<td class="width-35">
						<form:input path="ysxl" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">合同里程：</label></td>
					<td class="width-35">
						<form:input path="htlc" htmlEscape="false"    class="form-control "/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">客户特殊需求：</label></td>
					<td class="width-35">
						<form:input path="tsxq" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right">备注信息：</label></td>
					<td class="width-35">
						<form:input path="remarks" htmlEscape="false"    class="form-control "/>
					</td>

		  		</tr>
				<tr>

					<td class="width-15 active"><label class="pull-right">项目：</label></td>
					<td class="width-35">
						<form:input path="pro" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"></td>
					<td class="width-35" ></td>
				</tr>
		 	</tbody>
		</table>
		<div class="tabs-container">
            <ul class="nav nav-tabs">
				<li class="active"><a data-toggle="tab" href="#tab-3" aria-expanded="true">运输价格表：</a>
                </li>
				<li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">物料上浮：</a>
                </li>
				<li class=""><a data-toggle="tab" href="#tab-1" aria-expanded="false">绩效运价：</a>
                </li>
            </ul>
            <div class="tab-content">
				<div id="tab-1" class="tab-pane fade ">
			<a class="btn btn-white btn-sm" onclick="addRow('#achievementsList', achievementsRowIdx, achievementsTpl);achievementsRowIdx = achievementsRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
			<table class="table table-striped table-bordered table-condensed">
				<thead>
					<tr>
						<th class="hide"></th>
						<th>作业类型</th>
						<th>吨位区间</th>
						<th>绩效运价</th>
						<th>生效日期</th>
						<th>失效日期</th>
						<th width="10">&nbsp;</th>
					</tr>
				</thead>
				<tbody id="achievementsList">
				</tbody>
			</table>
			<script type="text/template" id="achievementsTpl">//<!--
				<tr id="achievementsList{{idx}}">
					<td class="hide">
						<input id="achievementsList{{idx}}_id" name="achievementsList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="achievementsList{{idx}}_delFlag" name="achievementsList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>
					
					<td>

					<select id="achievementsList{{idx}}_type" name="achievementsList[{{idx}}].type" data-value="{{row.type}}" class="form-control m-b  ">

							<c:forEach items="${fns:getDictList('workType')}" var="dict">
								<option value="${dict.value}">${dict.label}</option>
							</c:forEach>
						</select>
						<%--<input id="achievementsList{{idx}}_type" name="achievementsList[{{idx}}].type" type="text" value="{{row.type}}"    class="form-control "/>--%>
					</td>
					
					
					<td>
					<sys:gridselect url="${ctx}/infor/newWidth/data" id="achievementsList{{idx}}_width" name="achievementsList[{{idx}}].width.id" value="{{row.width.id}}" labelName="achievementsList[{{idx}}].width.width" labelValue="{{row.width.width}}"
							 title="选择吨位区间" cssClass="form-control required" fieldLabels="区间" fieldKeys="width" searchLabels="区间" searchKeys="width" />

					</td>
					
					
					<td>
						<input id="achievementsList{{idx}}_jxyj" name="achievementsList[{{idx}}].jxyj" type="text" value="{{row.jxyj}}"    class="form-control "/>
					</td>
					
					<td>
						<div class='input-group form_datetime' >
		                    <input type='text' id="achievementsList{{idx}}_qsrq" name="achievementsList[{{idx}}].qsrq" class="form-control "  value="{{row.qsrq}}"/>
		                    <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
		                    </span>
		                </div>
					</td>


					<td>
						<div class='input-group form_datetime' >
		                    <input type='text' id="achievementsList{{idx}}_jzrq" name="achievementsList[{{idx}}].jzrq" class="form-control "  value="{{row.jzrq}}"/>
		                    <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
		                    </span>
		                </div>
					</td>
					<%--<td>--%>
						<%--<input id="achievementsList{{idx}}_qsrq" name="achievementsList[{{idx}}].qsrq" type="text" value="{{row.qsrq}}"    class="form-control "/>--%>
					<%--</td>--%>
					<%----%>
					<%----%>
					<%--<td>--%>
						<%--<input id="achievementsList{{idx}}_jzrq" name="achievementsList[{{idx}}].jzrq" type="text" value="{{row.jzrq}}"    class="form-control "/>--%>
					<%--</td>--%>
					
					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#achievementsList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
			</script>
			<script type="text/javascript">
				var achievementsRowIdx = 0, achievementsTpl = $("#achievementsTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
				$(document).ready(function() {
					var data = ${fns:toJson(newCustomers.achievementsList)};
					for (var i=0; i<data.length; i++){
						addRow('#achievementsList', achievementsRowIdx, achievementsTpl, data[i]);
						achievementsRowIdx = achievementsRowIdx + 1;
					}
				});
			</script>
			</div>
				<div id="tab-2" class="tab-pane fade">
			<a class="btn btn-white btn-sm" onclick="addRow('#goodsCustomerList', goodsCustomerRowIdx, goodsCustomerTpl);goodsCustomerRowIdx = goodsCustomerRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
			<table class="table table-striped table-bordered table-condensed">
				<thead>
					<tr>
						<th class="hide"></th>
						<%--<th>物料编码</th>--%>
						<th>物料名称</th>
						<th>上浮比例</th>
						<th>上浮附加</th>
						<th>生效时间</th>
						<th>失效时间</th>
						<th width="10">&nbsp;</th>
					</tr>
				</thead>
				<tbody id="goodsCustomerList">
				</tbody>
			</table>
			<script type="text/template" id="goodsCustomerTpl">//<!--
				<tr id="goodsCustomerList{{idx}}">
					<td class="hide">
						<input id="goodsCustomerList{{idx}}_id" name="goodsCustomerList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="goodsCustomerList{{idx}}_delFlag" name="goodsCustomerList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>
					
					<%--<td>--%>
						<%--<input id="goodsCustomerList{{idx}}_code" name="goodsCustomerList[{{idx}}].code" type="text" value="{{row.code}}"    class="form-control "/>--%>
					<%--</td>--%>
					
					
					<td>
					<sys:gridselect url="${ctx}/infor/goods/data" id="goodsCustomerList{{idx}}_name" name="goodsCustomerList[{{idx}}].name.id" value="{{row.goods.id}}" labelName="goodsCustomerList[{{idx}}].name.name" labelValue="{{row.name.name}}"
							 title="选择物料" cssClass="form-control required" fieldLabels="名称" fieldKeys="name" searchLabels="物料编码" searchKeys="code" />

						<%--<input id="goodsCustomerList{{idx}}_name" name="goodsCustomerList[{{idx}}].name.id" type="text" value="{{row.name.id}}"    class="form-control "/>--%>
					</td>
					
					
					<td>
						<input id="goodsCustomerList{{idx}}_bl" name="goodsCustomerList[{{idx}}].bl" type="text" value="{{row.bl}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="goodsCustomerList{{idx}}_fj" name="goodsCustomerList[{{idx}}].fj" type="text" value="{{row.fj}}"    class="form-control "/>
					</td>
					

					<td>
						<div class='input-group form_datetime' >
		                    <input type='text' id="goodsCustomerList{{idx}}_qs" name="goodsCustomerList[{{idx}}].qs" class="form-control "  value="{{row.qs}}"/>
		                    <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
		                    </span>
		                </div>
					</td>


					<td>
						<div class='input-group form_datetime' >
		                    <input type='text' id="goodsCustomerList{{idx}}_jz" name="goodsCustomerList[{{idx}}].jz" class="form-control "  value="{{row.jz}}"/>
		                    <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
		                    </span>
		                </div>
					</td>
					<%--<td>--%>
						<%--<input id="goodsCustomerList{{idx}}_qs" name="goodsCustomerList[{{idx}}].qs" type="text" value="{{row.qs}}"    class="form-control "/>--%>
					<%--</td>--%>
					<%----%>
					<%----%>
					<%--<td>--%>
						<%--<input id="goodsCustomerList{{idx}}_jz" name="goodsCustomerList[{{idx}}].jz" type="text" value="{{row.jz}}"    class="form-control "/>--%>
					<%--</td>--%>
					
					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#goodsCustomerList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
			</script>
			<script type="text/javascript">
				var goodsCustomerRowIdx = 0, goodsCustomerTpl = $("#goodsCustomerTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
				$(document).ready(function() {
					var data = ${fns:toJson(newCustomers.goodsCustomerList)};
					for (var i=0; i<data.length; i++){
						addRow('#goodsCustomerList', goodsCustomerRowIdx, goodsCustomerTpl, data[i]);
						goodsCustomerRowIdx = goodsCustomerRowIdx + 1;
					}
				});
			</script>
			</div>
				<div id="tab-3" class="tab-pane fade in  active">
			<a class="btn btn-white btn-sm" onclick="addRow('#priceCustomersList', priceCustomersRowIdx, priceCustomersTpl);priceCustomersRowIdx = priceCustomersRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
			<table class="table table-striped table-bordered table-condensed">
				<thead>
					<tr>
						<th class="hide"></th>
						<th width="8%">作业类型</th>
						<th>结算吨位区间</th>
						<th>结算价格</th>
						<th>结算附加费</th>
						<th>特殊单价</th>
						<th>最大里程</th>
						<th>最小里程</th>
						<th>生效日期</th>
						<th>失效日期</th>
						<th width="10">&nbsp;</th>
					</tr>
				</thead>
				<tbody id="priceCustomersList">
				</tbody>
			</table>
			<script type="text/template" id="priceCustomersTpl">//<!--
				<tr id="priceCustomersList{{idx}}">
					<td class="hide">
						<input id="priceCustomersList{{idx}}_id" name="priceCustomersList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="priceCustomersList{{idx}}_delFlag" name="priceCustomersList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>
					
					<td>
						<select id="priceCustomersList{{idx}}_zylx" name="priceCustomersList[{{idx}}].zylx" data-value="{{row.zylx}}" class="form-control m-b  ">

							<c:forEach items="${fns:getDictList('workType')}" var="dict">
								<option value="${dict.value}">${dict.label}</option>
							</c:forEach>
						</select>
						<%--<input id="priceCustomersList{{idx}}_zylx" name="priceCustomersList[{{idx}}].zylx" type="text" value="{{row.zylx}}"    class="form-control "/>--%>
					</td>
					
					
					<td>
					<sys:gridselect url="${ctx}/infor/width/data" id="priceCustomersList{{idx}}_width" name="priceCustomersList[{{idx}}].width.id" value="{{row.width.id}}" labelName="priceCustomersList[{{idx}}].width.width" labelValue="{{row.width.width}}"
							 title="选择吨位区间" cssClass="form-control required" fieldLabels="区间" fieldKeys="width" searchLabels="区间" searchKeys="width" />

					</td>
					
					
					<td>
						<input id="priceCustomersList{{idx}}_jsjg" name="priceCustomersList[{{idx}}].jsjg" type="text" value="{{row.jsjg}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="priceCustomersList{{idx}}_fjf" name="priceCustomersList[{{idx}}].fjf" type="text" value="{{row.fjf}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="priceCustomersList{{idx}}_tsdj" name="priceCustomersList[{{idx}}].tsdj" type="text" value="{{row.tsdj}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="priceCustomersList{{idx}}_zdlc" name="priceCustomersList[{{idx}}].zdlc" type="text" value="{{row.zdlc}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="priceCustomersList{{idx}}_zxlc" name="priceCustomersList[{{idx}}].zxlc" type="text" value="{{row.zxlc}}"    class="form-control "/>
					</td>
						<td>
						<div class='input-group form_datetime' >
		                    <input type='text' id="priceCustomersList{{idx}}_ksrq" name="priceCustomersList[{{idx}}].ksrq" class="form-control "  value="{{row.ksrq}}"/>
		                    <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
		                    </span>
		                </div>
					</td>


					<td>
						<div class='input-group form_datetime' >
		                    <input type='text'id="priceCustomersList{{idx}}_jzrq" name="priceCustomersList[{{idx}}].jzrq" class="form-control "  value="{{row.jzrq}}"/>
		                    <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
		                    </span>
		                </div>
					</td>
					
					<%--<td>--%>
						<%--<input id="priceCustomersList{{idx}}_ksrq" name="priceCustomersList[{{idx}}].ksrq" type="text" value="{{row.ksrq}}"    class="form-control "/>--%>
					<%--</td>--%>
					<%----%>
					<%----%>
					<%--<td>--%>
						<%--<input id="priceCustomersList{{idx}}_jzrq" name="priceCustomersList[{{idx}}].jzrq" type="text" value="{{row.jzrq}}"    class="form-control "/>--%>
					<%--</td>--%>
					
					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#priceCustomersList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
			</script>
			<script type="text/javascript">
				var priceCustomersRowIdx = 0, priceCustomersTpl = $("#priceCustomersTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
				$(document).ready(function() {
					var data = ${fns:toJson(newCustomers.priceCustomersList)};
					for (var i=0; i<data.length; i++){
						addRow('#priceCustomersList', priceCustomersRowIdx, priceCustomersTpl, data[i]);
						priceCustomersRowIdx = priceCustomersRowIdx + 1;
					}
				});
			</script>
			</div>
		</div>
		</div>
		</form:form>
</body>
</html>